package com.vint.lintcode;

import java.util.Stack;

/*
 * 判断是否有有效括号对
 */
public class Lintcode423 {
    public boolean isValidParentheses(String s) {
        if (null == s) return true;
        Stack<Character> st = new Stack<>();
        char[] charS = s.toCharArray();
        for ( char c : charS) {
            if (c == '(' || c == '[' || c == '{') {
                st.add(c);
            } else {
                if (st.isEmpty())return false;
                char top = st.pop();
                if ( c == ')' && top == '(') {
                    continue;
                }
                if ( c == ']' && top == '[') {
                    continue;
                }
                if ( c == '}' && top == '{') {
                    continue;
                }
            }
        }
        if (st.isEmpty())return true;
        return false;
    }
}
